package com.braintreepayments.cardform.utils;

import ohos.vibrator.agent.VibratorAgent;
import ohos.vibrator.bean.VibrationPattern;

import java.util.List;

public class VibrationHelper {

    public static void vibrate() {
        VibratorAgent vibratorAgent = new VibratorAgent();
        // 查询硬件设备上的振动器列表
        List<Integer> vibratorList = vibratorAgent.getVibratorIdList();
        if (vibratorList.isEmpty()) {
            return;
        }
        int vibratorId = vibratorList.get(0);
        // 查询指定的振动器是否支持指定的振动效果
        boolean isSupport = vibratorAgent.isEffectSupport(vibratorId,
                VibrationPattern.VIBRATOR_TYPE_CAMERA_CLICK);
        if (isSupport) {
            // 创建指定效果的一次性振动
            vibratorAgent.startOnce(vibratorId, VibrationPattern.VIBRATOR_TYPE_CAMERA_CLICK);
        }
    }
}
